package cn.tedu.spring2205.week01.demo02;

import cn.tedu.spring2205.week01.demo02.config.Demo02Config;
import cn.tedu.spring2205.week01.demo02.controller.CatController;
import cn.tedu.spring2205.week01.demo02.dao.AnimalDao;
import cn.tedu.spring2205.week01.demo02.dao.BearDao;
import cn.tedu.spring2205.week01.demo02.dao.CatDao;
import cn.tedu.spring2205.week01.demo02.dao.UserDao;
import cn.tedu.spring2205.week01.demo02.service.CatService;
import cn.tedu.spring2205.week01.demo02.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;

public class Demo02Test {
    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(Demo02Config.class);
        //获取CatController实例
//        CatController controller = context.getBean("catController", CatController.class);
//        System.err.println(controller);

        //获取CatService实例
//        CatService catService = context.getBean("catService", CatService.class);
//        System.err.println(catService);
//        catService = context.getBean("catServiceImpl",CatService.class);
//        System.err.println(catService);

        //获取service中的Dao对象，查看@AutoWired是否注入成功
//        CatDao catDao = catService.getCatDao();
//        System.err.println(catDao);

        //测试构造方法@Autowried注入是否成功
//        AnimalDao animalDao = catService.getAnimalDao();
//        System.err.println(animalDao);

        //测试set方法@Autowried注入是否成功
//        BearDao bearDao = catService.getBearDao();
//        System.out.println(bearDao);

        //测试@Qualifier是否消除歧义
//        UserService userService = context.getBean(UserService.class);
//        System.err.println(userService);
//        UserDao userDao = userService.getUserDao();
//        System.err.println(userDao);

        //测试@Qualifier作用于set方法是否消除歧义
        UserService userService = context.getBean(UserService.class);
        UserDao userDao = userService.getUserDao();
        System.err.println(userDao);
    }
}
